﻿using System;

namespace Plug_in_Method
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] values = new int[] { 1, 2, 3 };
            Console.WriteLine("对values求平方");
            Util.TransForm(values, SquareTransFormer);
            foreach (var i in values)
                Console.WriteLine(i);
            Console.WriteLine("对values求立方");
            Util.TransForm(values, ThreeTransFormer);
            foreach (var i in values)
                Console.WriteLine(i);



        }

        static int SquareTransFormer(int value) => value * value;

        static int ThreeTransFormer(int value) => value * value * value;

    }

    public delegate int TransFormer(int x);

    public class Util
    {
        public static void TransForm(int[] values, TransFormer transFormer)
        {

            for (int i = 0; i < values.Length; i++)
            {
                values[i] = transFormer(values[i]);
            }
        }

    }
}
